$(function () {
    layui.use(['table','util'], function(){
        var table = layui.table,util=layui.util;
        table.render({
            elem: '#admin'
            ,url:'../../user/showAdmin',
            method:'POST'
            ,even:true
            ,cols: [[
                {field:'id', title: 'ID'}
                ,{field:'phone', title: '用户名'}
                ,{field:'password',  title: '登录密码'}
                ,{field:'createtime',title:'创建时间',templet: function(d) {return util.toDateString(d.createtime,"yyyy-MM-dd HH:mm:ss"); } }
                ,{ toolbar: '#barDemo',title:'编辑'}
            ]]
            ,page: false,
        });
        table.on('tool(event)',function (obj) {
            layer.confirm('确定删除该管理员吗,删除后不可撤回', function(index){
                var data = obj.data;
                $.ajax({
                    type: "POST",
                    url: "../../user/deleteAdmin",
                    data: {
                        "user_id":data.id
                    },
                    dataType: "json",
                    success: function(data){
                        if(data.code==0){
                            obj.del();
                            layer.close(index);
                        }
                        layer.msg(data.msg);
                    }
                });
            });
        })
    });
})
function showAdd() {
    layer.open({
        type: 2,
        title: '新增管理员',
        content: 'addAdmin.html',
        maxmin: false,
        area: ['500px', '250px'],
        end: function() {
        }
    });
}